//
//  Status.m
//  TuiTe
//
//  Created by 张 霄鹤 on 10-4-1.
//  Copyright 2010 xhzhang. All rights reserved.
//

#import "Status.h"


@implementation Status

@synthesize created_at;
@synthesize tid;
@synthesize text;
@synthesize source;
@synthesize truncated;
@synthesize favorited;
@synthesize unreaded;
@synthesize usr;

- (void)parse:(Element *)el{
	Node *nd = [el getChildByName:@"created_at"];
	if(nd){
		self.created_at = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"id"];
	if(nd){
		self.tid = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"text"];
	if(nd){
		// self.text = [[[nd getChildByName:@"#TEXT"] getValue] retain];
		Element *exx = (Element *)nd;
		NSArray *es = [exx getElementsByName:@"#TEXT"];
		if(es){
			NSMutableString *str = [[NSMutableString alloc] init];
			for(Node *dn in es){
				[str appendString:[dn getValue]];
			}
			self.text = str;
			[str release];
		}		
	}
	
	nd = [el getChildByName:@"source"];
	if(nd){
		self.source = [[nd getChildByName:@"#TEXT"] getValue];
	}
	
	nd = [el getChildByName:@"truncated"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];
		self.truncated = [ns isEqualToString:@"true"];
	}
	
	nd = [el getChildByName:@"favorited"];
	if(nd){
		NSString *ns = [[nd getChildByName:@"#TEXT"] getValue];		
		self.favorited = [ns isEqualToString:@"true"];
	}
	
	nd = [el getChildByName:@"user"];
	if(nd){
		User1 *u = [[User1 alloc] init];
		[u parse:(Element *)nd];
		self.usr = u;
		[u release];
	}
}

@end
